#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:zhangcong
# Email:zc_92@sina.com


from django import template
from django.utils.safestring import mark_safe
register = template.Library()

from webadmin.views_dir.mongo_oper import get_db_obj


# 获取创建用户的名称,表示谁创建了这个用户
@register.simple_tag
def get_create_username(user_data, create_user_id):
    if create_user_id:
        return user_data[create_user_id]
    else:
        return "系统"


@register.simple_tag
def get_roles_name(roles_data, role_id):
    if role_id:
        return roles_data[role_id]
    else:
        return "超级管理员"


# 获取_id, 模板语言取 obj._id 会报错
@register.simple_tag
def get_id(obj):
    return obj["_id"]


# 判断是不是上级权限id ,如果是则加上 selected 标签
@register.simple_tag
def is_pid(obj, o_id):
    if obj["_id"] == o_id:
        return "selected"


# @register.simple_tag
# def get_parent_name(rights_objs, obj):
#
#     print(dir(rights_objs.where), type(rights_objs.where))